//
//  DCAlipaySSOModule.m
//  LibWeexDCAlipaySSO
//
//  Created by yanyu on 2019/4/30.
//  Copyright © 2019 yanyu. All rights reserved.
//

#import "DCAlipaySSOModule.h"
#import <AFAuthSDK/AFAuthSDK.h>

@implementation DCAlipaySSOModule


@synthesize weexInstance;

WX_EXPORT_METHOD(@selector(login:callback:))

#pragma mark - Export Method

- (void)login:(NSDictionary *)options callback:(WXModuleKeepAliveCallback)callback
{
    /*
    //你在info中/或plist中设置的appScheme
    NSString *appScheme = @"你的appScheme";
    //authStr参数后台获取！和开发中心配置的app有关系，包含appid\name等等信息。
    NSString *authStr = @"后台获取的authStr";
    //没有安装支付宝客户端的跳到网页授权时会在这个方法里回调
    [[AFAuthSDK defaultService] authv2WithInfo:authStr fromScheme:appScheme callback:^(NSDictionary *result) {
        // 解析 auth code
        NSString *resultString = result[@"result"];
        NSString *authCode = nil;
        if (resultString.length>0) {
            NSArray *resultArr = [resultString componentsSeparatedByString:@"&"];
            for (NSString *subResult in resultArr) {
                if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
                    authCode = [subResult substringFromIndex:10];
                    break;
                }
            }
        }
        NSLog(@"resultString = %@",resultString);
        //        NSLog(@"authv2WithInfo授权结果 authCode = %@", authCode?:@"");
    }];
    */
    
    NSLog(@"执行");
    if (callback) {
        callback(@"",TRUE);
    }
    
}

@end
